package com.cv4j.app.fragment;

import ohos.aafwk.content.Intent;
import ohos.aafwk.content.Operation;
import ohos.agp.components.Component;
import ohos.agp.components.ComponentContainer;
import ohos.agp.components.Image;
import ohos.agp.components.LayoutScatter;
import ohos.app.Context;
import ohos.utils.IntentConstants;
import ohos.utils.net.Uri;

import com.cv4j.app.ResourceTable;
import com.cv4j.app.app.BaseFragment;


/**
 * HomeFragment
 *
 * @since 2021-05-14
 */
public class HomeFragment extends BaseFragment {
    private Context context;

    @Override
    protected Component onComponentAttached(LayoutScatter scatter, ComponentContainer container, Intent intent) {
        Component root = scatter.parse(ResourceTable.Layout_fragment_home, container, false);
        context = container.getContext();
        Image image = (Image) root.findComponentById(ResourceTable.Id_image);
        image.setClickedListener(component -> {
            String urlString = "https://www.apache.org/licenses/LICENSE-2.0.html";
            Intent intents = new Intent();
            Operation operation = new Intent.OperationBuilder()
                .withUri(Uri.parse(urlString))
                .withAction(IntentConstants.ACTION_SEARCH)
                .build();
            intents.setOperation(operation);
            context.startAbility(intents, 0);
        });
        return root;
    }

    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
    }

}
